import request from '@/network'

// 查询权限列表
export const queryRightsRequest = async () => {
  const result = await request.get({
    url: '/rights/list',
  })
  return result
}
// 获取权限列表id数组
export const queryRightsIdRequest = async () => {
  const result = await request.get({
    url: '/rights/key_list',
  })
  return result
}
// 根据角色id获取权限
export const queryRightsByRoleIdRequest = async (role_id: number | undefined) => {
  const result = await request.get({
    url: 'rights/role_key',
    params: {
      role_id,
    },
  })
  return result
}
// 获取角色列表
export const queryRoleListRequest = async (currentPage: number = 1, pageSize: number = 7) => {
  const result = await request.get({
    url: '/rights/role_list',
    params: {
      currentPage,
      pageSize,
    },
  })
  return result
}
// 更新角色权限
export const updateRoleRightsRequest = async (role_id: number, newKeys: number[]) => {
  const result = await request.post({
    url: '/rights/update_role_rights',
    data: {
      role_id,
      newKeys,
    },
  })
  return result
}
// 获取角色接口权限
export const queryInterfaceListRequest = async () => {
  const result = await request.get({
    url: '/rights/role_interface_list',
  })
  return result
}
// 根据角色id查询接口权限
export const queryInterfaceByRoleIdRequest = async (role_id: number | undefined) => {
  const result = await request.get({
    url: '/rights/role_interface_key',
    params: {
      role_id,
    },
  })
  return result
}
// 更新角色接口权限
export const updateRoleInterfaceRequest = async (newKeys: number[], role_id: number) => {
  const result = await request.post({
    url: '/rights/update_role_interface',
    data: {
      newKeys,
      role_id,
    },
  })
  return result
}
// 修改角色名称
export const updateRoleNameRequest = async (id: number, role_name: string) => {
  const result = await request.patch({
    url: '/rights/update_role_name',
    data: {
      id,
      role_name,
    },
  })
  return result
}
// 删除角色
export const deleteRoleRequest = async (id: number) => {
  const result = await request.delete({
    url: '/rights/delete_role',
    data: {
      id,
    },
  })
  return result
}
// 添加角色
export const addRoleRequest = async (name: string) => {
  const result = await request.post({
    url: '/rights/add',
    data: {
      name: name,
    },
  })
  return result
}
